class dd_trend:
    def __init__(self,factor=0.005):
        self.factor=factor#默认千1
        self.preb=None
        self.fx=0
    def oncalc(self,b,timekey=None):
        rst=None
        if self.preb:
            if b["low"]<self.preb["low"]*(1-self.factor):
                if self.fx>=0:#上涨中找顶
                    p=max(self.preb["open"],self.preb["close"])
                    if b["close"]<=p*(1-self.factor):
                        self.fx=-2
                    if self.fx==2:
                        self.fx==1
            elif b["high"]>self.preb["high"]*(1+self.factor):
                if self.fx<=0:#下跌中找堤
                    p=min(self.preb["open"],self.preb["close"])
                    if b["close"]>=p*(1+self.factor):
                        self.fx=2
                    if self.fx==-2:
                        self.fx==-1
        self.preb=b
        rst=self.fx
        return rst